<?php
class VerhuuritemsController extends AppController {

	var $name = 'Verhuuritems';
        var $helpers = array('Js' => array('Jquery'));


        function index() {
            $this->set('verhuuritems',  $this->Verhuuritem->find('all'));
            $this->setVariables();
	}

        function add(){
            if(!empty($this->data)){
                if($this->Verhuuritem->save($this->data)){
                    $this->Session->setFlash('Het verhuuritem is opgeslagen');
                    $this->redirect(array('action' => 'index'));
                }
            }
        }

        function view($id = null){
            $this->Verhuuritem->id=$id;
            $this->set('verhuuritem', $this->Verhuuritem->read());
        }

        function delete($id){
            if ($this->Verhuuritem->delete($id)) {
                $this->Session->setFlash('Het verhuuritem met id: ' . $id . ' werd verwijderd.');
                $this->redirect(array('action' => 'index'));
            }
        }

        function edit($id){
            $this->Verhuuritem->id=$id;
            if(empty($this->data)){
                $this->data=$this->Verhuuritem->read();
            }else{
                if ($this->Verhuuritem->save($this->data)) {
                    $this->Session->setFlash('Het verhuuritem werd upgedate.');
                    $this->redirect(array('action' => 'index'));
                }
            }
        }

        function addToCart($id){
            $this->layout='ajax';
            array_push($_SESSION['cartitems'], $id);
            $this->setVariables();
            $this->log("added ".$id." to cart", 'info');
        }

        function setVariables(){
            if(!isset($_SESSION['cartitems'])){
                $_SESSION['cartitems']=array();
            }
            $this->set('cartitems',$_SESSION['cartitems']);
        }

}
?>
